local sk__guiming = fk.CreateSkill {

  name = "sk__guiming",

  tags = { Skill.Limited, },

}



sk__guiming:addEffect(fk.EnterDying, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__guiming.name) and player.dying and
    player:usedSkillTimes(sk__guiming.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recover({
      who = player,
      num = math.max(#room.alive_players-player.hp, 0),
      recoverBy = player,
      skillName = sk__guiming.name,
    })
    local n = #room.alive_players
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p:isNude() and not p.dead then
        local cards = table.random(p:getCardIds("he"), math.random(n))
        room:throwCard(cards, sk__guiming.name, p, player)
      end
    end
  end,
})

return sk__guiming
